﻿using EPiServer.Core;

namespace EPiServer.Labs.MobilePack.Site
{
    public abstract class MobileBase : EditPage
    {
        public bool IsMainSitePage
        {
            get
            {
                return CurrentPage.PageTypeName == "[MobilePack] Mobile Site";
            }
        }

        public PageData GetSiteData() {

            if (CurrentPage != null)
            {
                return GetSiteData(CurrentPage);
            }
            return null;
        }

        public static PageData GetSiteData(PageData pd)
        {
            if (pd.PageTypeName == "[MobilePack] Mobile Site") return pd;
            else 
            {
                if (pd.ParentLink != PageReference.EmptyReference)
                {
                    return GetSiteData(DataFactory.Instance.GetPage(pd.ParentLink));
                }
                return pd;
            }
        }

        public static bool IsMobilePage(PageReference pref)
        {
            return DataFactory.Instance.GetPage(pref).PageTypeName.StartsWith("[MobilePack]");
        }

     
    }
}